package LeetCode.leetcode;

/**
 * 有效完全平方数  二分法 logN
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/17
 * @time: 16:43
 */
public class Test367有效的完全平方数 {
    public static void main(String[] args) {
        System.out.println(isPerfectSquare(15));

    }
    public static boolean isPerfectSquare(int num) {
        long start = 1;
        long end = num;

        while (start <= end) {
            long mid = (start + end) >>> 1;
            if (mid * mid == num) {
                return true;
            } else if (mid * mid < num){
                start = mid + 1;
            } else {
                end = mid - 1;
            }

        }
        return false;

    }
}
